from tgwebservices.controllers import WebServicesRoot, WebServicesController, \
                                      wsexpose, wsvalidate

from tgwebservices.runtime import typedproperty, unsigned

class FancyValue(object):
    "A person description"
    #: The name
    name = unicode
    #: The age
    age = int

    def computed(self):
        return "Hello!"

    #: A computed property
    computed = typedproperty(str, computed)

    def __init__(self, name=None, age=None):
        self.name = name
        self.age = age

    @classmethod
    def sample(cls):
        return FancyValue('Rimbaud', 27)

class FancyService(WebServicesController):
    "Fancy functions"
    @wsexpose(FancyValue)
    def getfancy(self):
        """
        Returns a fancy value

        :returns: The fancy value
        """
        fv = FancyValue()
        fv.name = "Mr. Test"
        fv.age = 33
        return fv

    @wsexpose()
    @wsvalidate(FancyValue)
    def setfancy(self, fancy):
        """Send a fancy value
        :param value: The sent fancy
        """
        return

class MyService(WebServicesRoot):
    "Basic functions"
    fancy = FancyService()

    @wsexpose(int)
    @wsvalidate(int)
    def times2(self, value):
        """
        Multiplies value by two.

        :param value: The value to multiply
        """
        return value * 2

    @wsexpose(int)
    @wsvalidate(int)
    def twentyover(self, value):
        """
        Divides 20 by value.

        :param value: The value to divide
        """
        return 20 / value

